﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GroupManager.ascx.cs" Inherits="FreshCms.BackEnd.Controls.Systems.GroupManager" %>
<div id="page-content" class="block">
    <div class="block-header">
        <a href="javascript:void(0)" class="header-title-link">
            <h1>Quản lý nhóm người dùng</h1>
        </a>
    </div>

    <div class="col-sm-4"></div>
    <div class="col-sm-4">
        <div class="block">
            <div class="block-title"><h2>Chức năng</h2></div>
            <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><i class="gi gi-group"></i></span>
                    <asp:TextBox ID="txtGroupName" runat="server" CssClass="form-control"></asp:TextBox>
                    <span class="input-group-addon">Tên nhóm</span>
                </div>
            </div>
            <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><i class="gi gi-rotation_lock"></i></span>
                    <asp:DropDownList ID="ddlStatus" runat="server" CssClass="form-control form-control-status" size="1"></asp:DropDownList>
                    <span class="input-group-addon">Trạng thái</span>
                </div>
            </div>
            <div class="form-group text-center">
                <%--<button type="button" id="btnSearch" class="btn btn-sm btn-primary"><i class="icon-search icon-fixed-width"></i>Tìm kiếm</button>--%>
                <button type="button" id="btnAdd" class="btn btn-sm btn-success"><i class="hi hi-plus mr5"></i>Thêm mới</button>
            </div>
        </div>
    </div>

    <div class="table-responsive">
        <table id="tblParent" class="table table-hover">
            <thead>
                <tr>
                    <th class="text-center" style="width: 60px;">
                        #
                    </th>
                    <th class="text-center" style="width: 60px;">
                        Id
                    </th>
                    <th>
                        Tên nhóm
                    </th>
                    <th style="width: 200px;">
                        Trạng thái
                    </th>
                    <th class="text-center" style="width: 200px;">
                        Thao tác
                    </th>
                </tr>
            </thead>
            <tbody>
                <asp:Repeater ID="rpt" runat="server">
                    <ItemTemplate>
                        <tr id="trMain_<%# Eval("GroupId") %>">
                            <td class="text-center"><%# Container.ItemIndex + 1 %></td>
                            <td class="text-center"><%# Eval("GroupId") %></td>
                            <td><%# Eval("GroupName") %></td>
                            <td><asp:Label ID="lblStatus" runat="server" Text=""></asp:Label></td>
                            <td class="text-center">
                                <div class="btn-group">
                                    <a href="/BackEnd/?ui=2&sui=1&groupid=<%# Eval("GroupId") %>" data-toggle="tooltip" title="" class="btn btn-xs btn-default"
                                        data-original-title="Phân quyền"><i class="gi gi-keys"></i></a>
                                    <a href="javascript:void(0)" data-toggle="tooltip" title="" class="btn btn-xs btn-default"
                                        data-original-title="Sửa" onclick="activeExtTR(<%# Eval("GroupId") %>)"><i class="gi gi-pen"></i></a>
                                    <div class="btn-group dropup text-left">
                                        <a href="javascript:void(0)" data-toggle="dropdown" class="btn btn-xs btn-default btn-danger dropdown-toggle"><i class="gi gi-remove_2"></i> </a>
                                        <ul class="dropdown-menu dropdown-menu-delete">
                                            <li><a href="javascript:void(0)" onclick="DeleteData(<%# Eval("GroupId") %>)" data-toggle="tooltip" data-original-title="Chú ý, xóa Nhóm người dùng thì các tài khoản thuốc nhóm này sẽ không đăng nhập được nữa...">Đồng ý</a></li>
                                            <li><a href="javascript:void(0)">Hủy</a></li>
                                        </ul>
                                    </div>
                            
                                </div>
                            </td>
                        </tr>
                        <tr id="trExt_<%# Eval("GroupId") %>" style="display:none/*table-row*/;">
                            <td class="text-center"><%# Container.ItemIndex + 1 %></td>
                            <td class="text-center"><%# Eval("GroupId") %></td>
                            <td><input type="text" id="txtGroupName_<%# Eval("GroupId") %>" class="form-control" value="<%# Eval("GroupName") %>"></td>
                            <td><asp:DropDownList ID="ddlStatus" runat="server" CssClass="form-control form-control-status" rel="status"></asp:DropDownList></td>
                            <td class="text-center">
                                <div class="btn-group">
                                    <a href="javascript:void(0)" data-toggle="tooltip" title="" class="btn btn-xs btn-default btn-success"
                                        data-original-title="Hoàn tất" onclick="UpdateData(<%# Eval("GroupId") %>)"><i class="hi hi-ok"></i></a>

                                    <a href="javascript:void(0)" data-toggle="tooltip" title="" class="btn btn-xs btn-default btn-primary" 
                                        data-original-title="Hủy" onclick="activeMainTR(<%# Eval("GroupId") %>)"><i class="hi hi-share-alt"></i></a>
                                </div>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
            </tbody>
        </table>
    </div>
</div>

<script>
    
    $(function() {
        // format color for drop down list
        FormatColorDropList('<%=ddlStatus.ClientID %>');
        
        // format cho cả list 
        $("#tblParent select[rel*='status']").each(function () {
            FormatColorDropList($(this).attr('id'));
        });
    });

    $("#btnAdd").bind("click", function () {
        if (!chkTextBox('<%=txtGroupName.ClientID %>', 'Bạn phải nhập tên nhóm...')) {
            return false;
        }
        if (!chkDropdownBox('<%=ddlStatus.ClientID %>', 'Bạn phải chọn trạng thái...')) {
            return false;
        }

        // call ajax
        var param;
        param = {
            m: "add",
            ui : <%=panelId %>,
            id: 0,
            name: $('#<%=txtGroupName.ClientID %>').val(),
            stt: $('#<%=ddlStatus.ClientID %>').val()
        };
        $.ajax({
            url: "/BackEnd/Handler/Group.ashx",
            data: param,
            type: "POST",
            dataType: "json",
            beforeSend: function () {
                jWaiting.callWaiting();
            },
            success: function (data) {
                //console.log(data);
                if (data.Success) {
                    jWaiting.callWaitingMessSuccess('Thêm mới nhóm người dùng thành công...', 'reload', true);
                }
                else {
                    jWaiting.callWaitingMessError('Có lỗi: ' + data.Message);
                }
            }
        });
    });

    // event Delete Fast in data table
    function DeleteData(id) {
        // call ajax
        var param;
        param = {
            m: "delete",
            ui : <%=panelId %>,
            id: id
        };
        $.ajax({
            url: "/BackEnd/Handler/Group.ashx",
            data: param,
            type: "POST",
            dataType: "json",
            beforeSend: function () {
                jWaiting.callWaiting();
            },
            success: function (data) {
                //console.log(data);
                if (data.Success) {
                    jWaiting.callWaitingMessSuccess('Xóa nhóm người dùng thành công...', 'reload', true);
                }
                else {
                    jWaiting.callWaitingMessError('Có lỗi: ' + data.Message);
                }
            }
        });
    }

    // event Update Fast in data table
    function UpdateData(id) {
        var $row = $('#trExt_' + id);
        var groupname = $('#txtGroupName_' + id).val();
        var groupstt = $row.find('select').val();

        // call ajax
        var param;
        param = {
            m: "add",
            ui : <%=panelId %>,
            id: id,
            name: groupname,
            stt: groupstt
        };
        $.ajax({
            url: "/BackEnd/Handler/Group.ashx",
            data: param,
            type: "POST",
            dataType: "json",
            beforeSend: function () {
                jWaiting.callWaiting();
            },
            success: function (data) {
                //console.log(data);
                if (data.Success) {
                    jWaiting.callWaitingMessSuccess('Cập nhật nhóm người dùng thành công...', 'reload', true);
                }
                else {
                    jWaiting.callWaitingMessError('Có lỗi: ' + data.Message);
                }
            }
        });
    }
</script>